// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 2008-7-6 19:22:23
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   CreateStrutsQueryMap.java

package com.creawor.generator;

import java.io.*;

// Referenced classes of package com.creawor.generator:
//            Config_bean, Sql_and_java_map

public class CreateStrutsQueryMap
{

    public CreateStrutsQueryMap(String table_nameP)
    {
        cb = new Config_bean();
        table_name = "";
        pojo_table_name = "";
        table_name = table_nameP.toLowerCase();
        pojo_table_name = table_nameP;
        map = new Sql_and_java_map(table_nameP);
    }

    public void writefile()
    {
        Config_bean _tmp = cb;
        Config_bean _tmp1 = cb;
        String pathname = (new StringBuilder(String.valueOf(Config_bean.path_name_j2src))).append("/").append(Config_bean.package_name.replace('.', '/')).append("/").append(table_name).append("/").toString();
        String Filename = (new StringBuilder(String.valueOf(table_name))).append("_QueryMap.java").toString();
       // System.out.println((new StringBuilder("\n")).append(pathname).append(Filename).toString());
        try
        {
            File p = new File(pathname);
            if(!p.exists() || !p.isDirectory())
                p.mkdirs();
            PrintWriter pw = new PrintWriter(new FileOutputStream((new StringBuilder(String.valueOf(pathname))).append(Filename).toString()));
            pw.println(getBeanCode());
            pw.close();
            //System.out.println((new StringBuilder("\nQueryMap\u4EE3\u7801\u6210\u529F\u751F\u6210:\n")).append(pathname).append(Filename).toString());
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
    }

    public String getHead()
    {
        Config_bean _tmp = cb;
        String str_tmp = (new StringBuilder("\n//\u7531\u751F\u6210\u5668\u751F\u6210\npackage ")).append(Config_bean.package_name).append(".").append(table_name).append(";\n").append("import java.util.Iterator;\n").append("import net.sf.hibernate.HibernateException;\n").append("import net.sf.hibernate.Session;\n").append("import net.sf.hibernate.Query;\n").append("import com.creawor.imei.base.AbsQueryMap;\n\n").append("public class ").append(table_name).append("_QueryMap extends AbsQueryMap {\n\n").append("public ").append(table_name).append("_QueryMap() throws HibernateException {\n").append("\tthis.initSession();\n").append("}\n\n").toString();
        return str_tmp;
    }

    public String getBody()
    {
        String str_tmp = (new StringBuilder("public Iterator findAll() throws HibernateException {\n\tthis.totalrow =\t((Integer) this.session.iterate(\"select count(*) from ")).append(pojo_table_name).append("\").next()).intValue();\n").append("\tString querystr = \"from ").append(pojo_table_name).append("\";\n").append("\tQuery query = this.session.createQuery(querystr);\n").append("    this.setQueryPage(query);\n").append("\treturn query.iterate();\n}\n").append("\npublic ").append(table_name).append("_Form getByID(String ID) throws HibernateException {\n").append(table_name).append("_Form  vo = null;\n").append("\n  System.out.println(\"\\n").append(table_name).append("_QueryMap getByID:\"+ID);\n\n").append("\tthis.session.clear();\n").append("\ttry {\n").append("\t\tvo =new ").append(table_name).append("_Form();\n").append("\t\t").append(pojo_table_name).append(" po=(").append(pojo_table_name).append(") this.session.load(").append(pojo_table_name).append(".class, new Integer(ID));\n").append(map.po2vo_Copy()).append("\t} catch (HibernateException e) {\n").append("\t\tSystem.out.println(\"\\nERROR in getByID @").append(pojo_table_name).append(":\" + e);\n").append("\t}\n").append("\treturn vo;\n").append("}\t\n\n").toString();
        return str_tmp;
    }

    public String getFoot()
    {
        return "}\n//\u7531\u751F\u6210\u5668\u751F\u6210";
    }

    public String getBeanCode()
    {
        return (new StringBuilder(String.valueOf(getHead()))).append(getBody()).append(getFoot()).toString();
    }

    Config_bean cb;
    public String table_name;
    public String pojo_table_name;
    public Sql_and_java_map map;
}